

class P776_39643 {

	
	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
            System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) { return (null);}
        if ((car < 0) && (buffer.length() == 0)) return (null);
        return (buffer.toString()).trim();
    }

	
	public static void main(String[] args) {
		
		char[][] grid = new char[1000][1000]; 
		int[][] gridAnswer = new int[1000][1000]; 
		
		
		String line = readLn();
		
		while (line != null) {
			int n = 0, m = 0;
			
			while (line != null && !"%".equals(line)) {
				
				m = 0;
				
				for (int k = 0; k < line.length(); k++) {
					char c = line.charAt(k);
					if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') {
						grid[n][m] = c;
						m++;
					}
					
				}
				
				n++;
				
				line = readLn();
			}
			
			int count = 1;
			
			for (int k = 0; k < n; k++) {
				for (int j = 0; j < m; j++) {
					char c = grid[k][j];
					if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') {
						flood(c, grid, k, j, n, m, count, gridAnswer);
						count++;
					}
					
				}
			}
			
			
			int[] spaces = new int[m];
			
			for (int j = 0; j < m; j++) {
				
				int max = 0;
				
				for (int k = 0; k < n; k++) {
					
					int numberLength = Integer.toString(gridAnswer[k][j]).length();
					
					if (max < numberLength) max = numberLength;
					
				}
				
				spaces[j] = max;
				
			}
			
			for (int k = 0; k < n; k++) {
				StringBuffer sb = new StringBuffer();
				sb.append(format(gridAnswer[k][0], spaces[0] - 1));
				for (int j = 1; j < m; j++) {
					sb.append(format(gridAnswer[k][j], spaces[j]));
				}
				System.out.println(sb.toString());
			}
			System.out.println("%");
			line = readLn();
			
		}
		
	}
	
	private static String format(int number, int length) {
		String n = Integer.toString(number);
		
		for (int k = n.length(); k <= length;  k++) {
			n = " " + n;
		}
		
		return n;
	}


	static void print(char[][] grid, int n, int m) {
		for (int k = 0; k < n; k++) {
			StringBuffer sb = new StringBuffer();
			for (int j = 0; j < m; j++) {
				sb.append(grid[k][j] + " ");
			}
			System.out.println(sb.toString().trim());
		}
	}
	
	private static void flood(char t, char[][] grid, int k, int j, int n, int m, int count, int[][] gridAnswer) {
		char c = grid[k][j];
		
		if (c == t && (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')) {
			grid[k][j] = '-';
			gridAnswer[k][j] = count;
		 
			if (k + 1 < n) flood(t, grid, k+1, j, n, m, count, gridAnswer);
			if (j + 1 < m) flood(t, grid, k, j+1, n, m, count, gridAnswer);
			
			if (k - 1 >= 0) flood(t, grid, k-1, j, n, m, count, gridAnswer);
			if (j - 1 >= 0) flood(t, grid, k, j-1, n, m, count, gridAnswer);
			
			if (k + 1 < n && j + 1 < m) flood(t, grid, k+1, j+1, n, m, count, gridAnswer);
			if (k - 1 >= 0 && j - 1 >= 0) flood(t, grid, k-1, j-1, n, m, count,  gridAnswer);
			
			if (k + 1 < n && j - 1 >= 0) flood(t, grid, k+1, j-1, n, m, count, gridAnswer);
			if (k - 1 >= 0 && j + 1 < m) flood(t, grid, k-1, j+1, n, m, count, gridAnswer);
			
		
		} 
	}
}
